package main

import (
	"fmt"
	"time"
)

// 时间和日期大都在 time 包中

func main() {
	//formatDate()
	unixTime()
}
func base() {
	//1.获取当前时间
	now := time.Now()
	//2021-09-12 20:52:13.831776 +0800 CST m=+0.000083147
	fmt.Println(now)
	//2021
	fmt.Println(now.Year())
	//September
	fmt.Println(now.Month())
	//9  直接通过 int 将英文月份转为数字
	fmt.Println(int(now.Month()))
	//12
	fmt.Println(now.Day())
	//20
	fmt.Println(now.Hour())
	//53
	fmt.Println(now.Minute())
	//53
	fmt.Println(now.Second())
	//219422000
	fmt.Println(now.Nanosecond())
	//2021 September 12
	fmt.Println(now.Date())
}
func formatDate() {
	now := time.Now()
	formatDate := fmt.Sprintf("%d-%d-%d %d:%d:%d\n", now.Year(), int(now.Month()), now.Day(),
		now.Hour(), now.Minute(), now.Second())
	fmt.Printf(formatDate)

	//now.Format 格式化，必须写这个时间【无语吧，我也无语】【按照612345记】
	format := now.Format("2006-01-02 15:04:05")
	fmt.Println(format)
	fmt.Println("年:", now.Format("2006"))
	fmt.Println("月", now.Format("01"))
	fmt.Println("日", now.Format("02"))
	fmt.Println("时", now.Format("15"))
	fmt.Println("分", now.Format("04"))
	fmt.Println("秒", now.Format("05"))

}
func constValue() {
	//Duration 中定义
	fmt.Println("1纳秒：", time.Nanosecond)
	fmt.Println("1微秒：", time.Microsecond)
	fmt.Println("1ms：", time.Millisecond)
	fmt.Println("1s：", time.Second)
	fmt.Println("1分钟：", time.Minute)
	fmt.Println("1小时：", time.Hour)

	// 这些常量用于获取指定大小的时间 ，如获取1000ms
	fmt.Println(1000 * time.Millisecond)

}

func sleepTest() {
	i := 1
	for {

		fmt.Println(i)
		if i == 10 {
			break
		}
		i += 1
		time.Sleep(time.Second)
	}
}

func unixTime() {
	now := time.Now()
	fmt.Println(now.Unix())
	fmt.Println(now.UnixNano())
}
